package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.service.GoodsTypeService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 里
 * @Description:
 */
@RestController
public class GoodsManageController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    /**
     * 查询商品所有分类
     * @return
     */
    @PostMapping("/goodsType/loadGoodsType")
    public String  getGoodsType() {
       return goodsTypeService.getGoodsType();
    }

    /**
     * 查询所有商品单位
     * @return
     */
    @PostMapping("/unit/list")
    public Map<String,Object> getGoodsUnitList() {
        return goodsTypeService.getGoodsUnitList();
    }


    /**
     * 查询所有商品信息
     * @return
     */
    @PostMapping("/goods/list")
    public Map<String,Object> getGoodsList(@Param("page")Integer page,
                                               @Param("rows")Integer rows,
                                               @Param("goodsName")String goodsName,
                                               @Param("goodsTypeId")Integer goodsTypeId) {
        return goodsTypeService.getGoodsList(page,rows,goodsName,goodsTypeId);
    }

    /**
     * 商品添加或修改
     * @param goods
     * @return
     */
    @PostMapping("/goods/save")
    public ServiceVO saveOrUpdateGoods(@RequestBody Goods goods) {
        goodsTypeService.saveOrUpdateGoods(goods);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    /**
     * 商品删除
     * @param goodsId
     * @return
     */
    @PostMapping("/goods/delete")
    public ServiceVO deleteGoodsById(@PathVariable("goodsId") Integer goodsId) {
        goodsTypeService.deleteGoodsById(goodsId);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    /**
     * 新增分类
     * @param goodsTypeName
     * @param pId
     * @return
     */
    @PostMapping("/goodsType/save")
    public ServiceVO saveGoodsType(@Param("goodsTypeName") String  goodsTypeName,@Param(("pId")) Integer  pId) {
        goodsTypeService.saveGoodsType(goodsTypeName,pId);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    /**
     * 删除分类
     * @param goodsTypeId
     * @return
     */
    @PostMapping("/goodsType/delete")
    public ServiceVO deleteGoodsType(@Param("goodsTypeId") Integer goodsTypeId) {
        goodsTypeService.deleteGoodsType(goodsTypeId);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    /**
     * 无库存商品列表展示（可以根据商品名称或编码查询）
     * @param page
     * @param rows
     * @param nameOrCode
     * @return
     */
    @PostMapping("/goods/getNoInventoryQuantity")
    public Map<String,Object> getNoInventoryQuantity(Integer page,Integer rows,String nameOrCode) {
            return goodsTypeService.getNoInventoryQuantity(page,rows,nameOrCode);
    }

    /**
     * 有库存商品列表展示（可以根据商品名称或编码查询）
     * @param page
     * @param rows
     * @param nameOrCode
     * @return
     */
    @PostMapping("/goods/getHasInventoryQuantity")
    public Map<String,Object> getHasInventoryQuantity(Integer page,Integer rows,String nameOrCode) {
        return goodsTypeService.getHasInventoryQuantity(page,rows,nameOrCode);
    }

    /**
     * 添加商品期初库存
     * @param goodsId 商品ID
     * @param inventoryQuantity 库存
     * @param purchasingPrice 成本价
     * @return
     */
    @PostMapping("saveStock")
    public ServiceVO saveStock(Integer goodsId,Integer inventoryQuantity,double purchasingPrice){
        return goodsTypeService.saveStock(goodsId,inventoryQuantity,purchasingPrice);
    }

    /**
     * deleteStock
     * 删除商品库存
     * @param goodsId 商品ID
     * @return
     */
    @PostMapping("deleteStock")
    public ServiceVO deleteStock(Integer goodsId){
        return goodsTypeService.deleteStock(goodsId);
    }
    /**
     * 查询库存报警商品信息
     * @return
     */
    @PostMapping("listAlarm")
    public Map<String,Object> listAlarm(){
        return goodsTypeService.listAlarm();
    }

}
